import React, {Component} from "react";
import {Col, Menu, Row} from "antd";
import {connect} from "react-redux";
import {actions as AdminAction} from '@/store/common/admin';
import {AdminConsole_mapStateToProps} from "../index";
import {renderRoutes} from "react-router-config";
import {actions} from "@/store/home/Article";
import {LightFontColor} from "@/style/Color";

class DataControl extends Component {
    constructor(props) {
        super(props);
        this.handleClick = this.handleClick.bind(this);
    }

    componentDidMount() {
        this.props.handleInitUserList();
    }

    handleClick(e) {
        switch (e.key) {
            case 'menu-1':
                this.props.handleInitUserList();
                this.props.history.push("/mine/admin/data-control/u-list");
                break;
            case 'menu-2':
                // 解决无返回数据的情况下会无终止的请求
                this.props.getHomeArticle();
                this.props.history.push("/mine/admin/data-control/a-list");
                break;
            default:
                break;
        }
    }

    render() {
        return (
            <Row gutter={[16.16]}>
                <Col span={24}>
                    <Menu style={{
                        backgroundColor: 'rgba(255,255,255,0)',
                        color: LightFontColor,
                        width: '30%',
                        margin: '10px auto',
                        borderBottom: 'none',
                        textAlign: 'center'
                    }}
                          onClick={(e) => this.handleClick(e)} defaultSelectedKeys={'menu-1'} mode="horizontal">
                        <Menu.Item key="menu-1">账户列表</Menu.Item>
                        <Menu.Item key="menu-2">文章列表</Menu.Item>
                        {/*<SubMenu key="menu-3" title="暂未开发" disabled>*/}
                        {/*    <Menu.ItemGroup title="Item 1" key='menu-4'>*/}
                        {/*        <Menu.Item key="menu-4-1">暂未开发</Menu.Item>*/}
                        {/*        <Menu.Item key="menu-4-2">暂未开发</Menu.Item>*/}
                        {/*    </Menu.ItemGroup>*/}
                        {/*    <Menu.ItemGroup title="Item 2" key='menu-5'>*/}
                        {/*        <Menu.Item key="menu-5-1">暂未开发</Menu.Item>*/}
                        {/*        <Menu.Item key="menu-5-2">暂未开发</Menu.Item>*/}
                        {/*    </Menu.ItemGroup>*/}
                        {/*</SubMenu>*/}
                        {/*<Menu.Item key="menu-6" disabled>*/}
                        {/*    暂未开发*/}
                        {/*</Menu.Item>*/}
                    </Menu>
                </Col>
                <Col span={24}>
                    {
                        renderRoutes(this.props.route.routes)
                    }
                </Col>
            </Row>
        )
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        handleInitUserList() {
            //saga事件
            dispatch(AdminAction.SAGA_QueryUserList)
        },
        getHomeArticle() {
            dispatch(actions.SagaQuery());
        }
    }
}
export default connect(AdminConsole_mapStateToProps, mapDispatchToProps)(DataControl);
